<?php
 include "counter2.php";

pagestart();
print "<html>\n<head>" .
"\n<!-- Attempt to get a half-hour refresh rate -->" .
"\n<meta http-equiv=\"Refresh\" content=\"1800\">\n";
pagehead("Hourly statistics", "head");
print "\n</head>" .

"\n<BODY bgcolor=\"white\">\n";
pagetop("Linux Counter Statistics");
print _("This is where I keep statistics about how well the counter runs. It's always going to be half baked.") .
"\n<p>\n" .
_("See also the") . " <a href=\"stats.php\">" . _("per-day statistics") . "</a>" .
"\n<p>\n" .
_("Statistics at ") . gmstrftime ("%b %d %Y %H:%M:%S",time()) . ":<br>";

if (!$days = $counter->get_input('days', 'number', 'get|post')) {
   $days = 1;
   $hours = 24;
} else {
   $hours = $days * 24;
}

print _("New persons last ") . $hours . _(" hours") . ": " .
dbcount("persons", "f_ctime > date_sub(now(), interval $days day)");
print "\n<br>\n";
print _("Updated persons last ") . $hours . _(" hours") . ": " .
dbcount("persons", "f_mtime > date_sub(now(), interval $days day) and f_mtime <> f_ctime");
print "\n<br>\n";
print _("Logins last ") . $hours . _(" hours") . ": " .
dbcount("users", "logintime > date_sub(now(), interval $days day)");
print "\n<br>\n";

print "<h2>" . _("Number of visitors per hour, last 3 days") . "</h2>" .
"\n<img src=\"visitorshour.png\" alt=\"" . _("Visitors per hour") . "\">" .
"\n<h2>" . _("Number of operations per hour, last 3 days") . "</h2>" .
"\n<img src=\"byhour.png\" alt=\"" . _("Operations per hour") . "\">";

print "\n<h2>" . _("Number of Web accesses per hour, last 3 days") . "</h2>" .
"\n<img src=\"wwwbyhour.png\" alt=\"" . _("Number of Web accesses per hour") . "\">" .

"\n<h2>" . _("Busiest countries for update and registration") . "</h2>\n" .
_("For the last ") . $hours . _(" hours");

print "\n<table border>" .
   "\n<tr>" .
       "\n<td>" .
       "\n<font size=\"4\"><b>" . _("Registrations") . "</b></font>" .
       "\n<table>" .
          "\n<tr>" .
              "\n<th>" . _("Count") . "</th>" .
              "\n<th>" . _("CC") . "</th>" .
              "\n<th align=left>" . _("Country") . "</th>" .
          "\n</tr>";

  $query = mysql_query('SELECT COUNT(*) AS c, country, places.longname FROM persons, places WHERE persons.f_ctime > DATE_SUB(NOW(), INTERVAL '. $days .' DAY) AND places.name = country GROUP BY country ORDER BY c desc LIMIT 10');
  while ($arr = mysql_fetch_row($query)) {

          print "\n<tr>" .
              "\n<td>" . $arr[0] . "</td>" .
              "\n<td>" . $arr[1] . "</td>" .
              "\n<td>" . $arr[2] . "</td>" .
          "\n</tr>";

  }

       print "\n</table>" .
       "\n</td>" .
       "\n<td>" .
       "\n<font size=\"4\"><b>" . _("Updates") . "</b></font>" .
       "\n<table>" .
          "\n<tr>" .
              "\n<th>" . _("Count") . "</th>" .
              "\n<th>" . _("CC") . "</th>" .
              "\n<th align=left>" . _("Country") . "</th>" .
          "\n</tr>";

  $query = mysql_query('SELECT COUNT(*) AS c, country, places.longname FROM persons, places WHERE persons.f_mtime > DATE_SUB(NOW(), INTERVAL '. $days.' DAY) AND persons.f_mtime <> persons.f_ctime AND places.name = country GROUP BY country ORDER BY c desc LIMIT 10');
  while ($arr = mysql_fetch_row($query)) {

          print "\n<tr>" .
              "\n<td>" . $arr[0] . "</td>" .
              "\n<td>" . $arr[1] . "</td>" .
              "\n<td>" . $arr[2] . "</td>" .
          "\n</tr>";

  }

       print "\n</table>" .
       "\n</td>" .
   "\n</tr>" .
"\n</table>";
pagebottom("yes");
print "\n</body>\n</html>"
?>
